package cn.doit.scala.day02.demo

import scala.io.{BufferedSource, Source}

/**
 * @DATE 2021/12/25/15:27
 * @Author MDK
 * @Version 2021.2.2
 * */
object ScoreDemo02 {
  def main(args: Array[String]): Unit = {
    //加载本地数据
    val source: BufferedSource = Source.fromFile("data/stu.txt")
    //获取行数据  并进行封装数据
    val lines: Iterator[String] = source.getLines()
    val res: Iterator[Student] = for (line <- lines) yield {
      val arr: Array[String] = line.split("\\s+")
      val str: Student = Student(arr(0), arr(1), arr(2).toDouble)
      str
    }
    //获取指定个人的成绩
    for (stu <- res) {
      val name: String = stu.name
      if("娜娜".equals(name)){
        println(s"${stu.subject}  ${stu.score}")
      }
    }

  }
}
